<!--表格公共组件-->
<template>
  <!-- 在此修改为table表格的使用说明
菜单组件说明
功能说明： 1、列表中基本数据显示，特殊类型数据展示，包括（）；

                    XINT			json.Number					整型
                    XSTR			json.String					字符串	"XXX"
                    XSTRS			json.Array<String>	字符串列表		["XXX","YYY",...]
                    XOPT			json.String					枚举<值,显示文本;...>，单选，不可为空		"XXX"
                    XOPTS			json.Array<String>	复杂枚举<值,显示文本;...>		["XXX","YYY",...]
                    XTIME			json.String					UTC时间		"XXX"
                    XBOOL			json.Bool						布尔<true,显示文本;false,显示文本>	true
                    XCERT			json.Object					证书		{}
                    XRAW			json.Object					原始数据	{}
                    XQUOTER<>	json.Array<String>	引用<目标地址>	["XXX","YYY",...]

            2、 操作列： 修改、删除、查看、授权、审计功能。
参数说明：
  {
        tableData:列表填充的数据，
        keyName： 接口中键值，默认"XPRO_ARRAY"（xpro2.0统一为XPRO_ARRAY）
        hasData:  默认为false，即调用组件中的获取列表数据的方法；如果设置为true，即从父组件中获取tableData数据。
        tableHeadList: [
            { colDisabled: false,
              colHidden: false,
              colSearch: true,
              colSort: false,
              columnComment: "标签类型",
              typeCollection:,如果列表展示的是数组类型:array,为枚举类型时:ENUM,为布尔类型:boolean,不是这三种类型类则不需要配置
              arrayName 为数组类型或者对象时想要.到的数据名称(例如 xxx.name,只需传name即可)
              columnName: "labelType"},
         ], table表格th处名称 key值为columnName
        totalCount:0,列表总数量
        tableLoading:true,表格是否加载
        tableHeight:xxx,表格高度
        pageSize：10,表格页数
        pageNum:1,表格当前页
        pageSizes：[5, 10, 20, 50, 100],分页数量列表
        isShowSelect:true,是否显示复选框
        pageShow:true,是否显示分页
        handleShow:true,是否显示操作列
        mergeFlag:false,是否合并单元格

        searchForm: 为查询列表，查询参数
      },
-->
  <div class="page-table deviceTable">
    <!--表格-->
    <el-table
      border
      :data="tableData_"
      ref="tableDataRef"
      style="width: 100%"
      v-loading="tableLoading"
      :height="tableHeight"
      row-key="id"
      :span-method="objectSpanMethod"
      @cell-mouse-leave="cellMouseLeave"
      @cell-mouse-enter="cellMouseEnter"
      :row-class-name="tableRowClassName"
      @select="selectTableData"
      @select-all="selectTableData"
    >
      <el-table-column
        v-if="isShowSelect"
        type="selection"
        width="55"
        align="center"
        :reserve-selection="true"
      >
      </el-table-column>
      <el-table-column
        type="index"
        width="60"
        label="序号"
        :index="indexMethod"
        align="center"
      ></el-table-column>
      <template v-for="(item, index) in tableHeadList">
        <el-table-column
          v-if="
            item.customStyle === 'slot' &&
            !item.colHidden &&
            item.typeCollection
          "
          :prop="item.columnName"
          :label="item.columnComment"
          :render-header="labelHead"
          :key="index"
          align="center"
          :sortable="item.colSort"
        >
          <template slot-scope="scope">
            <!-- 自定义列表项 -->
            <slot :name="item.slotName" :row="scope.row" :index="scope.$index">
            </slot>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="!item.colHidden && !item.typeCollection"
          :prop="item.columnName"
          :label="item.columnComment"
          :key="index"
          align="center"
          :sortable="item.colSort"
          :render-header="labelHead"
        >
          <template slot-scope="scope">
            <!--不为对象时过滤数据-->
            <p style="margin: 0" v-if="item.columnName == 'keyType'">
              {{ E_keyType[scope.row.keyType] }}
            </p>
            <p v-else-if="item.columnName == 'USecLevel'">
              <span v-show="scope.row[item.columnName] == 0">未知</span>
              <span v-show="scope.row[item.columnName] == 1">内部</span>
              <span v-show="scope.row[item.columnName] == 2">秘密</span>
              <span v-show="scope.row[item.columnName] == 3">机密</span>
              <span v-show="scope.row[item.columnName] == 4">绝密</span>
            </p>
            <p v-else-if="item.columnName == 'CurStatus'">
              <span v-show="scope.row[item.columnName] == 3"> 禁用 </span>
              <span v-show="scope.row[item.columnName] == 4"> 启用 </span>
            </p>
            <p v-else-if="item.columnName == 'DevType'">
              {{ E_devType[scope.row.keyType] }}
            </p>
            <p v-else-if="item.columnUsers == '2'">普通用户</p>
            <p style="margin: 0" v-else>
              {{ scope.row[item.columnName] | defaultText }}
            </p>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="item.typeCollection == 'TimeStamp'"
          :prop="item.columnName"
          :label="item.columnComment"
          :key="index"
          align="center"
          :sortable="item.colSort"
          :render-header="labelHead"
        >
          <template slot-scope="scope">
            <!--时间转换-->
            <p style="margin: 0">{{ scope.row.TimeStamp | TimeStamp }}</p>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="item.typeCollection == 'LevelEnum'"
          :prop="item.columnName"
          :label="item.columnComment"
          :key="index"
          align="center"
          :sortable="item.colSort"
          :render-header="labelHead"
        >
          <template slot-scope="scope">
            <!--枚举--等级告警-->
            <p style="margin: 0">{{ scope | objectText(item) }}</p>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="item.typeCollection == 'stateEnum'"
          :prop="item.columnName"
          :label="item.columnComment"
          :key="index"
          align="center"
          :sortable="item.colSort"
          :render-header="labelHead"
        >
          <template slot-scope="scope">
            <!--枚举--策略状态-->
            <p style="margin: 0">{{ scope | StatusText(item) }}</p>
          </template>
        </el-table-column>
      </template>
      <!-- 自定义插入一列 -->
      <el-table-column
        align="center"
        v-if="ifShowAddColumn"
        :label="addColumnLable"
        :width="addColumnWidth"
      >
        <!--slot可以根据需求插入-->
        <template slot-scope="scope">
          <!-- 自定义操作按钮项 -->
          <slot name="addColumn" :row="scope.row" :index="scope.$index"></slot>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        v-if="ifShowOnline"
        :label="addOnline"
        :width="addColumnWidth"
      >
        <!--slot可以根据需求插入-->
        <template slot-scope="scope">
          <!-- 自定义操作按钮项 -->
          <el-switch
            @change="statusChange($event, scope.row)"
            v-model="scope.row.state"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-value="1"
            inactive-value="0"
          >
          </el-switch>
        </template>
      </el-table-column>
      <!-- 操作列 -->
      <el-table-column
        type="handle"
        :width="handleWidth"
        align="center"
        v-if="handleShow"
        fixed="right"
      >
        <template slot="header" slot-scope="scope" class="handleShow">
          <span class="action">操作</span>
          <el-popover
            placement="bottom"
            min-width="100"
            trigger="hover"
            v-if="false"
          >
            <el-button
              slot="reference"
              size="small"
              type="text"
              icon="el-icon-setting"
              style="padding: 0; float: right; margin: 4.5px 0px"
            ></el-button>
            <div class="col-setting-title">
              <span style="font-size: 16px; font-weight: bolder"
                >表格字段定制</span
              >
              <el-button
                style="padding-left: 20px"
                type="text"
                @click="saveColOptions"
                >保存
              </el-button>
            </div>
            <el-checkbox-group v-model="colOptions">
              <el-checkbox
                v-for="(item, index) in colSelect"
                :label="item.columnName"
                :key="index"
                :disabled="item.colDisabled"
                style="margin-left: 10px !important"
              >
                {{ item.columnComment }}
              </el-checkbox>
            </el-checkbox-group>
          </el-popover>
        </template>
        <!--slot可以根据需求插入-->
        <template slot-scope="scope">
          <!-- 自定义操作按钮项 -->
          <slot name="handle" :row="scope.row" :index="scope.$index"></slot>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="modifys"
            icon="el-icon-edit"
            @click.native.prevent="modify(scope.row)"
            >修改
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            v-show="modisee"
            class="edit-button"
            icon="el-icon-star-off"
            @click.native.prevent="seeDetails(scope.row)"
            >查看
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="authorization"
            icon="el-icon-share"
            @click.native.prevent="impower(scope.row)"
            >授权
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="delete-button"
            v-show="deletes"
            icon="el-icon-delete"
            @click.native.prevent="delete1(scope.row)"
            >删除
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            class="delete-button"
            v-show="deletebtn"
            icon="el-icon-delete"
            @click.native.prevent="deleteHandle(scope.row)"
            >删除
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="auditStatus"
            icon="el-icon-s-check"
            @click.native.prevent="audit(scope.row)"
            :disabled="scope.row.audit_flag == 'auditSuccess'"
            >审计
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="baddxtsd"
            @click.native.prevent="bangdings(scope.row)"
            >绑定
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="baddxtsd"
            @click.native.prevent="bnagjiebags(scope.row)"
            >解绑
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="baddtsd"
            @click.native.prevent="deleclike"
            >删除
          </el-button>
          <el-button
            type="text"
            v-if="!ifShowAddColumns"
            size="small"
            class="edit-button"
            v-show="baddtsd"
            @click.native.prevent="jiebangd(scope.row)"
            >修改
          </el-button>
          <!--<el-button type="text"  size="small" class="delete-button"-->
          <!--icon="el-icon-delete" @click.native.prevent="delete(scope.row)">删除-->
          <!--</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <div v-if="pageShow" class="pagination-container">
      <el-pagination
        background
        :current-page.sync="comPageNum"
        :page-sizes="pageSizes"
        :page-size="comPageSize"
        layout="total,sizes,prev,pager,next,jumper"
        :total="totalCount_"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
    <!--详情对话框-->
    <el-dialog
      title="详情信息"
      :visible.sync="dialogVisible"
      width="width"
      :before-close="dialogBeforeClose"
    >
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="详情信息" name="first">
          <el-form ref="form" :model="form" label-width="180px">
            <template v-for="(item, index) in seeTableData">
              <el-col :span="12">
                <el-form-item :label="item.columnComment">
                  <span class="spanBack">
                    <span v-if="item.seename != ''">{{ item.valueName }}</span>
                    <span v-else>----</span>
                  </span>
                </el-form-item>
              </el-col>
            </template>
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { E_keyType, E_devType } from "../../assets/js/enum";
import { parseTime } from "@/assets/js/time";
export default {
  name: "comTable",
  data() {
    return {
      dialogVisible: false,
      colOptions: [], //可见列
      colSelect: [], //选择
      E_keyType: E_keyType,
      E_devType: E_devType,
      comPageNum: this.pageNum, //当前页
      comPageSize: this.pageSize, //每页条数
      comSearchForm: this.searchForm,
      multiColumnCount: {},
      rowIndex: "-1",
      hoverOrderArr: [], //鼠标移入时的数据
      orderIndexArr: [], //获取相同编号数组
      seeTableData: [],
      tableData_: JSON.parse(JSON.stringify(this.tableData)),
      totalCount_: JSON.parse(JSON.stringify(this.totalCount)),
      tableHeadList_: JSON.parse(JSON.stringify(this.tableHeadList)),
      form: {},
      activeName: "first",
      textData: {
        SOURCE: "来源",
        CLASS: "密级",
        LEVEL: "分级",
        CATEGORY: "分类",
        TIME: "时间",
        WHITE: "白名单",
        BLACK: "黑名单",
        success: "成功",
        fail: "失败",
        auditSuccess: "已审计",
        auditFail: "未审计",
      },
      booleanData: {
        true: "启用",
        false: "停用",
      },
      userName: "",
    };
  },
  props: {
    //是否显示新加的列
    ifShowAddColumn: {
      type: Boolean,
      default: false,
    },
    ifShowAddColumns: {
      type: Boolean,
      default: false,
    },
    // 列表显示开关
    ifShowOnline: {
      type: Boolean,
      default: false,
    },
    addOnline: {
      type: String,
      default: "",
    },
    // 是否开启 ip
    isIpshow: {
      type: Boolean,
      default: false,
    },

    //新加的列宽度
    addColumnWidth: {
      type: String,
      default: "",
    },
    //新加的列标签名
    addColumnLable: {
      type: String,
      default: "",
    },
    //操作列宽度
    handleWidth: {
      type: String,
      default: "200",
    },
    //父组件是否传递列表数据
    hasData: {
      type: Boolean,
      default: false,
    },
    //获取数据的url
    url: {
      type: String,
      default: "",
    },
    //名称
    keyName: {
      type: String,
      default: "XPRO_ARRAY",
    },
    //授权显示
    authorization: {
      type: Boolean,
      default: false,
    },
    //授权显示
    modifys: {
      type: Boolean,
      default: false,
    },
    modisee: {
      type: Boolean,
      default: false,
    },
    //授权显示
    deletes: {
      type: Boolean,
      default: false,
    },
    deletebtn: {
      type: Boolean,
      default: false,
    },
    // 身份鉴别
    baddtsd: {
      type: Boolean,
      default: false,
    },
    baddxtsd: {
      type: Boolean,
      default: false,
    },
    //审计状态切换
    auditStatus: {
      type: Boolean,
      default: false,
    },
    //表体数据
    tableData: {
      type: Array,
      default: () => [], // 注意不能去掉括号
    },
    //表头数据
    tableHeadList: {
      type: Array,
      default: () => [], // 注意不能去掉括号
    },
    //查询数据
    searchForm: {
      type: Object,
      default: () => ({}), // 注意不能去掉括号
    },
    //列表总量
    totalCount: {
      type: Number,
      default: 0,
    },
    //每页条数
    pageSize: {
      type: Number,
      default: 100,
    },
    //当前页
    pageNum: {
      type: Number,
      default: 1,
    },
    //分页数量列表
    pageSizes: {
      type: Array,
      default: () => [], // 注意不能去掉括号
    },
    //是否显示复选框
    isShowSelect: {
      type: Boolean,
      default: false,
    },
    //是否表格加载
    tableLoading: {
      type: Boolean,
      default: false,
    },
    //表格高度
    tableHeight: {
      type: Number,
      default: 0,
    },
    //是否显示分页
    pageShow: {
      type: Boolean,
      default: false,
    },
    //是否显示操作栏
    handleShow: {
      type: Boolean,
      default: true,
    },
    //表名ID
    tableId: {
      type: String,
      default: "",
    },
    //是否合并
    mergeFlag: {
      type: Boolean,
      default: false,
    },
    //合并依据
    mergeBase: {
      type: Array,
      default: () => [], // 注意不能去掉括号
    },
    /**
     * 要进行相同数据行合并的字段键值，如第一行和第二行的dict值一样想要进行合并，则可以将dict字段传入此字段['dict']
     * 数组含有selection:支持复选框合并。
     * 数组含有handle:支持操作栏合并
     *
     * */
    mergeRowKeys: {
      type: Array,
      default: () => [], // 注意不能去掉括号
    },
  },
  created() {
    this.getCheckDatas();
    this.userName = window.sessionStorage.getItem("userName");
  },
  mounted() {
    console.log(this.tableHeadList, "tableHeadList");
    if (!this.hasData) {
      //组件中调用获取数据列表的接口
      this.getTableData(this.comPageNum, this.comPageSize);
    }
  },
  watch: {
    colOptions: function (val) {
      //取this.colSelect的columnName集合
      let columnNameArr = [];
      this.colSelect.forEach((item) => {
        columnNameArr.push(item.columnName);
      });
      let arr = columnNameArr.filter((i) => val.indexOf(i) < 0); //未选中
      this.tableHeadList.filter((i, index) => {
        if (arr.indexOf(i.columnName) !== -1) {
          i.colHidden = true;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        } else {
          i.colHidden = false;
          this.$nextTick(() => {
            this.$refs.tableDataRef.doLayout();
          });
        }
      });
      //通知表单组件表头数据修改
      //bus.$emit("tableHeadChange", this.tableHeadList);
      //  通知父组件更改表格高度
      this.$emit("setSearchHeight");
    },
    // 监听父组件传来的数据，动态改变子组件中使用的变量,解决渲染不上的问题
    tableHeadList: function (val) {
      this.getCheckDatas();
    },
    tableData: function () {
      if (this.hasData) {
        this.tableData_ = this.tableData;
        this.totalCount_ = this.totalCount;
      }
      if (this.mergeFlag) {
        this.initMergeRow();
        this.getOrderNumber();
      }
    },
    //监听pageNum和pageSize,改变copy值
    pageNum: function (val) {
      console.log(val, "起始页数");
      this.comPageNum = val;
    },
    pageSize: function (val) {
      console.log(val, "大小");
      this.comPageSize = val;
    },
    // searchForm: function (val) {
    //   console.log(val,446)
    //   let comSearchForm = val
    //   this.comSearchForm =val
    //   this.getTableData(this.comPageNum, this.comPageSize,comSearchForm)
    // },
    ifShowAddColumn: function () {
      //列表重新加载
      if (this.$refs.tableDataRef !== undefined) {
        this.$nextTick(() => {
          this.$refs.tableDataRef.doLayout();
        });
      }
    },
  },
  methods: {
    /**
     * 获取表格数据
     * @param pageNum 当前页
     * @param pageNum 每页显示条数
     */
    getTableData(pageNum, pageSize, comSearchForm) {
      console.log(this.comPageNum, "起始页");
      console.log(pageSize, pageNum);
      this.loading = true;
      let key = this.keyName;
      let num = "XPRO_COUNT";
      let url = this.url + `?page=${pageNum}&count=${pageSize}`; // + (pageNum - 1) + "&pageSize=" + pageSize;

      let params = { filters: [] };
      console.log(comSearchForm, "comSearcForm");
      if (comSearchForm != undefined) {
        let keyss = Object.keys(comSearchForm);
        console.log(keyss, "keyss");
        for (let index = 0; index < keyss.length; index++) {
          let element = keyss[index];
          console.log(element, 89);
          let valus = comSearchForm[element];

          // params.filters.push({
          //   name:element,
          //   value:valus
          // })
          if (comSearchForm[element] == "") {
            url;
          } else {
            url += `&${element}=` + valus;
          }
        }
      }
      console.log(params, "params");
      this.$get(url).then((res) => {
        console.log(res, 642);
        let flag = res.data.data.Root.LogVioNet
        console.log(111111111111111111111111111111111111111111111)
        console.log(111111111111111111111111111111111111111111111)
        console.log(flag)
        if (flag) {
          let { page, data } = res.data;
          this.tableData_ = flag;
          if (page !== undefined) {
            this.totalCount_ = page.Total;
            this.$emit("totalCount", res.data.XPRO_COUNT);
          } else {
            this.totalCount_ = data.length;
            this.$emit("totalCount", res.data.XPRO_COUNT);
          }
          this.loading = false;
          return false
        }
        let { errcode, page, data } = res.data;
        this.loading = false;
        // if (!res.statusText == "OK") {
        //   this.$message.warning(res.data.msg);
        //   return;
        // }
        console.log(data.LogIOControl, "data1");
        let resData;
        // if (
        //   Object.prototype.toString.call(res.data.data) == "[object Object]"
        // ) {
        //   res.data.data.device = [res.data.data.device];
        //   this.totalCount_ = res.data.data.device.length;
        // }
        //
        // resData = res.data;
        this.$emit("listRow", resData);
        let lg = data.length;
        var array = [];
        for (let i = 0; i < lg; i++) {
          let item = data[i].Root;
          console.log(item, "Root");
          let keyValue = {};

          if (key == "Results") {
            //针对results中包裹数据的情况
            keyValue = item.Results.Result;
          } else if (key == "Object,Subject") {
            let objectValue = item.Object;
            let sujectValue = item.Subject;
            keyValue = Object.assign(objectValue, sujectValue);
          } else {
            keyValue = item[key];
          }
          // if (key == "Object") {
          //   //Object
          //   keyValue = item.Object;
          // } else {
          //   keyValue = item[key];
          // }
          // if (key == "LogAdminOper") {
          //   //Object
          //   keyValue = item.LogAdminOper;
          // } else {
          //   keyValue = item[key];
          // }

          console.log(keyValue, "keyValue");
          let obj = Object.assign(item, keyValue);
          // array.push(item);

          array.push(obj);
          console.log(array, "array");
        }

        if (key == "LogIOControl") {
          this.tableData_ = data.LogIOControl;
        } else if (key == "LogVioOper") {
          this.tableData_ = data.Root.LogVioOper;
        } else {
          this.tableData_ = array;
        }
        if (page !== undefined) {
          this.totalCount_ = page.Total;
          this.$emit("totalCount", res.data.XPRO_COUNT);
        } else {
          this.totalCount_ = data.length;
          this.$emit("totalCount", res.data.XPRO_COUNT);
        }
        // this.$nextTick(() => {
        //   this.$refs.tableDataRef.doLayout();
        // });
      });
    },

    impower(row) {
      this.$emit("ifImpower", row);
    },
    seeDetails(row) {
      console.log(row, this.tableHeadList_, "row");
      var seeData = [];
      console.log(row, "adsad");
      for (let key in row) {
        this.tableHeadList.forEach((item) => {
          if (key == item.columnName) {
            switch (item.typeCollection) {
              case "XBOOL":
                let a = row[key];
                let bull = "";
                if (a == true) {
                  bull = item.show_true;
                } else if (a == false) {
                  bull = item.show_false;
                }
                console.log(a, bull, "bullasddddd");
                bull = bull ? bull : "----";
                seeData.push({
                  seename: row[key],
                  columnComment: item.columnComment + "：",
                  valueName: bull,
                });
                break;
              case "XOPT":
              case "XOPTS":
                let b = row[key];
                let neum = "";
                item.display_enum.forEach((i) => {
                  if (i.value == b) {
                    return (neum += i.show);
                  }
                });
                neum = neum ? neum : "----";
                seeData.push({
                  seename: row[key],
                  columnComment: item.columnComment + "：",
                  valueName: neum,
                });

                break;
              case "XQUOTER":
                let value = row[key];
                console.log(value, "value");
                let result = "";
                for (let j of item.qekey) {
                  value.forEach((i) => {
                    console.log(i[j], "1244");
                    result += i[j] + "，";
                  });
                }
                result = result.substring(0, result.length - 1);
                result = result ? result : "---";
                seeData.push({
                  seename: row[key],
                  columnComment: item.columnComment + "：",
                  valueName: result,
                });
                break;
              case "XSTR":
                let values = row[key];
                values = values ? values : "---";
                seeData.push({
                  seename: row[key],
                  columnComment: item.columnComment + "：",
                  valueName: values,
                });
                break;
              default:
                seeData.push({
                  seename: "------",
                  columnComment: item.columnComment + "：",
                  valueName: "-----",
                });
                break;
            }
          }
        });
      }
      this.seeTableData = seeData;
      console.log(this.seeTableData, "seetaf");
      this.dialogVisible = true;
    },
    dialogBeforeClose() {
      this.seeTableData = [];
      this.dialogVisible = false;
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },

    /**
     * 修改
     * */
    modify(row) {
      console.log(row, 890);
      let url = row.XPRO_PATH;
      //调父组件中的修改功能：显示对话框，填入信息，点击“确定”，提示信息。
      this.$emit("openDialog", "update", row);
    },
    /**
     *
     * 审计操作
     * yymm特有功能
     * */
    audit(row) {
      var date = new Date();
      var mon = date.getMonth() + 1;
      var day = date.getDate();
      var myHour = date.getHours(); //获取当前小时数(0-23)
      var myMinute = date.getMinutes(); //获取当前分钟数(0-59)
      var mySecond = date.getSeconds();
      var currDate =
        date.getFullYear() +
        "-" +
        (mon < 10 ? "0" + mon : mon) +
        "-" +
        (day < 10 ? "0" + day : day) +
        "    " +
        myHour +
        ":" +
        (myMinute < 10 ? "0" + myMinute : myMinute) +
        ":" +
        (mySecond < 10 ? "0" + mySecond : mySecond);
      console.log(currDate, 123456);
      let url = row.XPRO_PATH;
      let params = {};
      params.audit_admin = window.sessionStorage.getItem("userName");
      params.audit_flag = "auditSuccess";
      params.audit_time = currDate;
      // this.$postForJson(url, params).then((jsonData) => {
      //   this.dialogControl = false;
      //   this.loading = false;
      //   let datas = jsonData.data;
      //   if (!datas.success) {
      //     this.publicModal.$emit("tips", {
      //       show: true,
      //       publicModalMessage: datas.msg,
      //       fontIcon: "errorWarning",
      //     });
      //     return false;
      //   }
      //   //上报功能
      //   this.auditReport(row.XPRO_PATH);
      //   this.$message({
      //     message: "审计成功",
      //     type: "success",
      //   });
      //   this.getTableData(this.comPageNum, this.comPageSize);
      // });
    },

    /**
     * 上报功能
     * yymm特有功能
     */
    auditReport(val) {
      let array = val.split("/");
      console.log(array);
      let type = array[array.length - 2].split(".")[0];
      let num = array[array.length - 2].split(".")[1];
      let url =
        "functions/logservice/logaudit/logupload?logtype=" +
        type +
        "&logid=" +
        num;
      this.$post(url).then((res) => {
        if (!res.data.success) {
          this.publicModal.$emit("tips", {
            show: true,
            publicModalMessage: res.data.msg,
            fontIcon: "errorWarning",
          });
        }
      });
    },
    /**
     * 删除
     * 删除前进行判断是否有引用
     * */
    delete1(row) {
      console.log(row, 8907778);
      let quote = row.XPRO_QUOTEE;
      console.log(!quote, "quote");
      if (quote.length > 0) {
        this.$message.warning("该对象存在其他引用，不能被删除");
        return;
      }
      this.$confirm("是否确定删除?", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        closeOnClickModal: false,
        type: "warning",
      }).then(() => {
        let url = row.XPRO_PATH;
        this.$delete(url).then((res) => {
          console.log(res, 780);
          //if (res.data.success) {
          //let resData = res.data.data;
          this.$message.success("删除成功");
          if (this.hasData) {
            this.$emit(
              "getTableData", // 需要父组件设置该事件，后端分页查询事件别名
              this.comPageNum,
              this.comPageSize
            );
          } else {
            this.getTableData(this.comPageNum, this.comPageSize);
          }
          //}
        });
      });
    },
    statusChange(val, row) {
      console.log(val, 621);
      console.log(row, 622);
      this.$emit("isOnline", val, row);
    },

    /*解决设备列表表头不换行问题（结合列表公共样式）*/
    labelHead(h, { column, index }) {
      let l = column.label.length;
      let f = 16;
      column.minWidth = f * (l + 2); //加上一个文字长度
      return h("span", { class: "table-head", style: { width: "100%" } }, [
        column.label,
      ]);
    },
    //存储可配置项及已配置项
    getCheckDatas() {
      let _this = this;
      //清空原有选择
      _this.colSelect = [];
      _this.colOptions = [];
      for (let i = 0; i < _this.tableHeadList.length; i++) {
        _this.colSelect.push(_this.tableHeadList[i]);
        if (!_this.tableHeadList[i].colHidden) {
          _this.colOptions.push(_this.tableHeadList[i].columnName);
        }
      }
    },
    //表格序号
    indexMethod(index) {
      let currentIndex = index + this.comPageNum;
      if (this.comPageNum !== 1) {
        let page = (this.comPageNum - 1) * this.comPageSize;
        currentIndex = index + 1 + page;
      }
      return currentIndex;
    },
    //切换每页显示条数时触发
    handleSizeChange(val) {
      console.log(val, "切换条数");
      this.comPageNum = 1;
      this.comPageSize = val;
      this.$emit("getTabpation", this.comPageNum, this.comPageSize);
      this.handleChange();
    },
    //切换页码时触发
    handleCurrentChange(val) {
      console.log(val, 942);
      this.comPageNum = val;
      this.$emit("getTabpation", this.comPageNum, this.comPageSize);
      this.handleChange();
    },
    //页码相关变动通知父组件
    handleChange() {
      //组件中获取列表数据
      if (!this.hasData) {
        this.getTableData(this.comPageNum, this.comPageSize, this.searchForm);
        return;
      }

      if (this.searchForm) {
        //如果有查询条件，传入条件参数
        this.$emit(
          "getTableData",
          this.comPageNum,
          this.comPageSize,
          this.searchForm
        );
      } else {
        this.$emit(
          "getTableData", // 需要父组件设置该事件，后端分页查询事件别名
          this.comPageNum,
          this.comPageSize
        );
      }
    },
    //排序
    //sortTableData(val) {
    //  根据val.prop和val.order构造条件排序
    //this.$emit(
    // "sortTableData", // 需要父组件设置该事件，
    // val
    //);
    //},
    //  选择
    selectTableData(selection) {
      console.log(selection, "选择");
      this.$emit(
        "selectTableData", // 需要父组件设置该事件，
        selection
      );
    },
    //向后端保存表格字段显示配置
    saveColOptions() {
      //将表头配置中的下拉框数据格式由数组转换为字符串
      this.tableHeadList.forEach((item, index) => {
        if (item.element === "el-select" && item.options) {
          item.options = item.options.toString();
        }
      });
      console.log(this.tableHeadList, 290);
      this.tableHeadList.forEach((item) => {
        item.dynamicColumnUnit = item.dynamicColumnUnit.name;
      });
      //保存配置到后端
      // this.$postForJson('dynamic/column/batchUpdate.do', this.tableHeadList).then(res => {
      //   console.log(res, 279)
      //   if (res.data.success) {
      //     //通知父组件更新表格数据
      //     this.$emit(
      //       "getColList", // 需要父组件设置该事件，后端分页查询事件别名
      //     );
      //   }
      // });
    },
    //初始化需要合并的单元格
    initMergeRow() {
      if (this.mergeRowKeys.length === 0) {
        return;
      }
      this.mergeRowKeys.forEach((key) => {
        const rowAndColumm = [];
        let pos = 0;
        for (let i = 0; i < this.tableData_.length; i++) {
          if (i === 0) {
            //如果是第一条记录（即索引是0的时候，向数组中加入1）
            rowAndColumm.push(1);
            pos = 0;
          } else {
            if (
              this.tableData_[i][this.mergeBase] !== "" &&
              this.tableData_[i - 1][this.mergeBase] !== "" &&
              this.tableData_[i][this.mergeBase] ===
                this.tableData_[i - 1][this.mergeBase]
            ) {
              //如果属性值相等就累加，并且push 0
              rowAndColumm[pos] += 1;
              rowAndColumm.push(0);
            } else {
              //不相等
              rowAndColumm.push(1);
              pos = i;
            }
          }
        }
        this.multiColumnCount[key] = rowAndColumm;
      });
    },
    //  合并单元格
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      //行合并
      //仅合并数据项
      if (this.mergeRowKeys.includes(column.property)) {
        if (this.multiColumnCount[column.property][rowIndex]) {
          const rowNum = this.multiColumnCount[column.property][rowIndex];
          return {
            rowspan: rowNum,
            colspan: rowNum > 0 ? 1 : 0,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
      //  合并复选框和操作栏
      if (this.mergeRowKeys.includes(column.type)) {
        if (this.multiColumnCount[column.type][rowIndex]) {
          const rowNum = this.multiColumnCount[column.type][rowIndex];
          return {
            rowspan: rowNum,
            colspan: rowNum > 0 ? 1 : 0,
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    //获取相同编号的数组
    getOrderNumber() {
      let orderObj = {};
      this.tableData_.forEach((item, index) => {
        item.rowIndex = index;
        if (item[this.mergeBase]) {
          if (orderObj[item[this.mergeBase]]) {
            orderObj[item[this.mergeBase]].push(index);
          } else {
            orderObj[item[this.mergeBase]] = [];
            orderObj[item[this.mergeBase]].push(index);
          }
        }
      });
      this.orderIndexArr = orderObj;
    },
    /**
     *  鼠标移入移出：解决进入表格时阴影样式问题
     * */
    cellMouseLeave(row, column, cell, event) {
      this.rowIndex = "-1";
      this.hoverOrderArr = [];
    },
    cellMouseEnter(row, column, cell, event) {
      this.rowIndex = row.rowIndex;
      this.hoverOrderArr = [];
      for (let key in this.orderIndexArr) {
        if (key === row[this.mergeBase]) {
          this.hoverOrderArr = this.orderIndexArr[row[this.mergeBase]];
        }
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (this.hoverOrderArr.includes(rowIndex)) {
        return "success-row";
      }
    },
    toggleSelection() {
      this.$refs.tableDataRef.clearSelection();
    },
    bangdings(row) {
      let gods = true;
      this.$emit("chooseData", gods, row);
    },
    bnagjiebags(data) {
      let gods = true;
      this.$emit("cobnabagsata", gods, data);
    },
    jiebangd(row) {
      this.$emit("chobangd", "updata", row);
    },
    deleclike() {
      this.$emit("deldngd", "");
    },
    deleteHandle(row) {
      this.$emit("deleteHandle", row);
    },
  },
  filters: {
    Timeconversion(value) {
      let time = "" + (Number(value.replace("Z", "")) + 80000);

      return time.replace(
        /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g,
        "$1-$2-$3 $4:$5:$6"
      );
    },
    defaultText(value) {
      if ((value == "") & (value !== false) & (value !== 0)) {
        return "---";
      } else {
        return value;
      }
    },
    filterTime(value) {
      var date = new Date(value * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      var Y = date.getFullYear() + "-";
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var D = date.getDate() + " ";
      var h = date.getHours() + ":";
      var m = date.getMinutes() + ":";
      var s = date.getSeconds();
      return Y + M + D + h + m + s;
    },
    //十位时间戳转换格式
    TimeStamp(value) {
      if ((value == "") & (value !== false) & (value !== 0)) {
        return "---";
      } else {
        return parseTime(value);
      }
    },
    //策略状态吗，枚举
    StatusText(scope) {
      console.log(scope.row.state, "item1-Status");
      switch (scope.row.state) {
        case "1":
          return "启用";
        case "0":
          return "禁用";

        default:
          return "---";
      }
    },
    //枚举--等级告警
    objectText(scope, item) {
      console.log(scope.row.Level, "item1的level值");
      console.log(item, "item");
      switch (scope.row.Level.toString()) {
        case "0":
          return "紧急";
        case "1":
          return "报警";
        case "2":
          return "关键";
        case "3":
          return "错误";
        case "4":
          return "警告";
        case "5":
          return "通知";
        case "6":
          return "信息";
        case "7":
          return "调试";

        default:
          return "---";
      }
    },

    //引用类型
    quoterText(scope, item) {
      //   let key = item.qekey[0];//引用值现在为一个数组，现只取第一个值
      let value = scope.row[scope.column.property];
      let result = "";
      for (let j of item.qekey) {
        value.forEach((i) => {
          result += i[j] + "，";
        });
      }
      result = result.substring(0, result.length - 1);
      return result ? result : "---";
    },
    enumText(scope, item, textData) {
      console.log(item);
      let a = scope.row[scope.column.property];
      let neum = "";
      item.display_enum.forEach((i) => {
        if (i.value == a) {
          return (neum += i.show);
        }
      });
      return neum ? neum : "----";
    },
    booleanText(scope, item, booleanText) {
      let a = scope.row[scope.column.property];
      let bull = "";
      if (a == true) {
        bull = item.show_true;
      } else if (a == false) {
        bull = item.show_false;
      }
      return bull ? bull : "----";
    },
  },
};
</script>

<style scoped>
@import "../../assets/css/commonTable.css";
</style>
<!-- // 自定义表格相关 -->
<style scoped>
.page-table .pagination-container {
  padding-top: 10px;
  text-align: center;
}
</style>
